import '../models/map_location.model.dart';
import '../models/map_poi.model.dart';
import './http_request_service.service.dart';

class MapService {
  /// Queries map location from map api by coordinate.
  Future<MapLocation?> queryByCoordinate(
      double latitude, double longitude) async {
    final response =
        await HttpRequestService.get('/mapLocation/queryByCoordinate', params: {
      'latitude': latitude,
      'longitude': longitude,
    });

    if (response.payload != null) {
      return MapLocation.fromJson(response.payload);
    } else {
      return null;
    }
  }

  /// Queries poi from map api by keywords.
  Future<List<MapPoi>> queryPoiByKeywords(String keywords) async {
    final response = await HttpRequestService.get(
        '/mapLocation/queryPoiByKeywords',
        params: {'keywords': keywords});

    return (response.payload as List<dynamic>)
        .map((p) => MapPoi.fromJson(p))
        .toList();
  }
}
